using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Microblaze.Simulator.Engine;

namespace Weazel.Microblaze.Simulator.Components.Microblaze.Instructions
{
    public class Put : Instruction
    {
        private enum PutInstructionKind
        {
            None,
            put,
            nput,
            cput,
            ncput
        }

        private PutInstructionKind kind;

        public override int CycleCount
        {
            get { return 2; }
        }

        public Put()
            : base("put")
        {
        }

        public uint Fls
        {
            get { return Value & 0x00000007; }
        }

        public override void Set(uint address, uint value)
        {
            base.Set(address, value);

            uint sub_opcode = value & 0x0000F000;

            kind =
              (sub_opcode == 0x00000000) ? PutInstructionKind.put :
              (sub_opcode == 0x00004000) ? PutInstructionKind.nput :
              (sub_opcode == 0x00002000) ? PutInstructionKind.cput :
              (sub_opcode == 0x00006000) ? PutInstructionKind.ncput :
              PutInstructionKind.None;

            if (kind == PutInstructionKind.None)
                throw new UnknownInstructionException(value);
        }

        public override void Execute(MicroblazeComponent MicroblazeComponent)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public override string ToString()
        {
            return string.Format("{0} r{1}, {2}",
              kind,
              SourceRegisterA,
              Fls
            );
        }
    }
}
